package com.luncheng.mcp.core.strategy;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.luncheng.mcp.core.model.McpClientConfig;
import com.luncheng.mcp.core.model.McpServerConfig;
import io.modelcontextprotocol.client.transport.ServerParameters;
import io.modelcontextprotocol.client.transport.StdioClientTransport;
import io.modelcontextprotocol.server.transport.StdioServerTransportProvider;
import io.modelcontextprotocol.spec.McpClientTransport;
import io.modelcontextprotocol.spec.McpServerTransportProvider;

public class StdioTransportStrategy implements TransportStrategy {
    @Override
    public McpClientTransport createClientTransport(McpClientConfig mcpClientConfig) {
        ServerParameters params = ServerParameters.builder(mcpClientConfig.getCommand())
                .args(mcpClientConfig.getStdioArgs())
                .env(mcpClientConfig.getEnv())
                .build();
        return new StdioClientTransport(params);
    }

    @Override
    public McpServerTransportProvider createServerTransport(ObjectMapper objectMapper, McpServerConfig config) {
        return new StdioServerTransportProvider(objectMapper);
    }
}